package com.dianping.cat.consumer.transaction.model.transform;

import com.dianping.cat.consumer.transaction.model.IEntity;
import com.dianping.cat.consumer.transaction.model.IVisitor;
import com.dianping.cat.consumer.transaction.model.entity.AllDuration;
import com.dianping.cat.consumer.transaction.model.entity.Duration;
import com.dianping.cat.consumer.transaction.model.entity.Graph;
import com.dianping.cat.consumer.transaction.model.entity.Graph2;
import com.dianping.cat.consumer.transaction.model.entity.GraphTrend;
import com.dianping.cat.consumer.transaction.model.entity.Machine;
import com.dianping.cat.consumer.transaction.model.entity.Range;
import com.dianping.cat.consumer.transaction.model.entity.Range2;
import com.dianping.cat.consumer.transaction.model.entity.StatusCode;
import com.dianping.cat.consumer.transaction.model.entity.TransactionName;
import com.dianping.cat.consumer.transaction.model.entity.TransactionReport;
import com.dianping.cat.consumer.transaction.model.entity.TransactionType;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  22 */   private Stack<Object> m_objs = new Stack();

  private TransactionReport m_transactionReport;


  public DefaultMerger() {}

  public DefaultMerger(TransactionReport transactionReport) {
/*  30 */     this.m_transactionReport = transactionReport;
    this.m_objs.push(transactionReport);
  }


/*  35 */   public TransactionReport getTransactionReport() { return this.m_transactionReport; }



/*  39 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  43 */     this.m_objs.push(to);
/*  44 */     from.accept(this);
/*  45 */     this.m_objs.pop();
  }


/*  49 */   protected void mergeAllDuration(AllDuration to, AllDuration from) { to.mergeAttributes(from); }



/*  53 */   protected void mergeDuration(Duration to, Duration from) { to.mergeAttributes(from); }



/*  57 */   protected void mergeGraph(Graph to, Graph from) { to.mergeAttributes(from); }



/*  61 */   protected void mergeGraph2(Graph2 to, Graph2 from) { to.mergeAttributes(from); }



/*  65 */   protected void mergeGraphTrend(GraphTrend to, GraphTrend from) { to.mergeAttributes(from); }



/*  69 */   protected void mergeMachine(Machine to, Machine from) { to.mergeAttributes(from); }


  protected void mergeName(TransactionName to, TransactionName from) {
/*  73 */     to.mergeAttributes(from);
/*  74 */     to.setSuccessMessageUrl(from.getSuccessMessageUrl());
/*  75 */     to.setFailMessageUrl(from.getFailMessageUrl());
/*  76 */     to.setLongestMessageUrl(from.getLongestMessageUrl());
  }


/*  80 */   protected void mergeRange(Range to, Range from) { to.mergeAttributes(from); }



/*  84 */   protected void mergeRange2(Range2 to, Range2 from) { to.mergeAttributes(from); }



/*  88 */   protected void mergeStatusCode(StatusCode to, StatusCode from) { to.mergeAttributes(from); }


  protected void mergeTransactionReport(TransactionReport to, TransactionReport from) {
/*  92 */     to.mergeAttributes(from);
/*  93 */     to.getDomainNames().addAll(from.getDomainNames());
/*  94 */     to.getIps().addAll(from.getIps());
  }

  protected void mergeType(TransactionType to, TransactionType from) {
/*  98 */     to.mergeAttributes(from);
/*  99 */     to.setSuccessMessageUrl(from.getSuccessMessageUrl());
/* 100 */     to.setFailMessageUrl(from.getFailMessageUrl());
/* 101 */     to.setLongestMessageUrl(from.getLongestMessageUrl());
  }


  public void visitAllDuration(AllDuration from) {
/* 106 */     AllDuration to = (AllDuration)this.m_objs.peek();

/* 108 */     mergeAllDuration(to, from);
/* 109 */     visitAllDurationChildren(to, from);
  }


  protected void visitAllDurationChildren(AllDuration to, AllDuration from) {}


  public void visitDuration(Duration from) {
/* 117 */     Duration to = (Duration)this.m_objs.peek();

/* 119 */     mergeDuration(to, from);
/* 120 */     visitDurationChildren(to, from);
  }


  protected void visitDurationChildren(Duration to, Duration from) {}


  public void visitGraph(Graph from) {
/* 128 */     Graph to = (Graph)this.m_objs.peek();

/* 130 */     mergeGraph(to, from);
/* 131 */     visitGraphChildren(to, from);
  }


  protected void visitGraphChildren(Graph to, Graph from) {}


  public void visitGraph2(Graph2 from) {
/* 139 */     Graph2 to = (Graph2)this.m_objs.peek();

/* 141 */     mergeGraph2(to, from);
/* 142 */     visitGraph2Children(to, from);
  }


  protected void visitGraph2Children(Graph2 to, Graph2 from) {}


  public void visitGraphTrend(GraphTrend from) {
/* 150 */     GraphTrend to = (GraphTrend)this.m_objs.peek();

/* 152 */     mergeGraphTrend(to, from);
/* 153 */     visitGraphTrendChildren(to, from);
  }


  protected void visitGraphTrendChildren(GraphTrend to, GraphTrend from) {}


  public void visitMachine(Machine from) {
/* 161 */     Machine to = (Machine)this.m_objs.peek();

/* 163 */     mergeMachine(to, from);
/* 164 */     visitMachineChildren(to, from);
  }

  protected void visitMachineChildren(Machine to, Machine from) {
/* 168 */     for (TransactionType source : from.getTypes().values()) {
/* 169 */       TransactionType target = to.findType(source.getId());

/* 171 */       if (target == null) {
/* 172 */         target = new TransactionType(source.getId());
/* 173 */         to.addType(target);
      }

/* 176 */       this.m_objs.push(target);
/* 177 */       source.accept(this);
/* 178 */       this.m_objs.pop();
    }
  }


  public void visitName(TransactionName from) {
/* 184 */     TransactionName to = (TransactionName)this.m_objs.peek();

/* 186 */     mergeName(to, from);
/* 187 */     visitNameChildren(to, from);
  }

  protected void visitNameChildren(TransactionName to, TransactionName from) {
/* 191 */     for (Range source : from.getRanges().values()) {
/* 192 */       Range target = to.findRange(source.getValue());

/* 194 */       if (target == null) {
/* 195 */         target = new Range(source.getValue());
/* 196 */         to.addRange(target);
      }

/* 199 */       this.m_objs.push(target);
/* 200 */       source.accept(this);
/* 201 */       this.m_objs.pop();
    }

/* 204 */     for (Duration source : from.getDurations().values()) {
/* 205 */       Duration target = to.findDuration(source.getValue());

/* 207 */       if (target == null) {
/* 208 */         target = new Duration(source.getValue());
/* 209 */         to.addDuration(target);
      }

/* 212 */       this.m_objs.push(target);
/* 213 */       source.accept(this);
/* 214 */       this.m_objs.pop();
    }

/* 217 */     for (Graph source : from.getGraphs().values()) {
/* 218 */       Graph target = to.findGraph(source.getDuration());

/* 220 */       if (target == null) {
/* 221 */         target = new Graph(source.getDuration());
/* 222 */         to.addGraph(target);
      }

/* 225 */       this.m_objs.push(target);
/* 226 */       source.accept(this);
/* 227 */       this.m_objs.pop();
    }

/* 230 */     for (AllDuration source : from.getAllDurations().values()) {
/* 231 */       AllDuration target = to.findAllDuration(source.getValue());

/* 233 */       if (target == null) {
/* 234 */         target = new AllDuration(source.getValue());
/* 235 */         to.addAllDuration(target);
      }

/* 238 */       this.m_objs.push(target);
/* 239 */       source.accept(this);
/* 240 */       this.m_objs.pop();
    }

/* 243 */     if (from.getGraphTrend() != null) {
/* 244 */       GraphTrend target = to.getGraphTrend();

/* 246 */       if (target == null) {
/* 247 */         GraphTrend source = from.getGraphTrend();

/* 249 */         target = new GraphTrend(source.getDuration());
/* 250 */         to.setGraphTrend(target);
      }

/* 253 */       this.m_objs.push(target);
/* 254 */       from.getGraphTrend().accept(this);
/* 255 */       this.m_objs.pop();
    }

/* 258 */     for (StatusCode source : from.getStatusCodes().values()) {
/* 259 */       StatusCode target = to.findStatusCode(source.getId());

/* 261 */       if (target == null) {
/* 262 */         target = new StatusCode(source.getId());
/* 263 */         to.addStatusCode(target);
      }

/* 266 */       this.m_objs.push(target);
/* 267 */       source.accept(this);
/* 268 */       this.m_objs.pop();
    }
  }


  public void visitRange(Range from) {
/* 274 */     Range to = (Range)this.m_objs.peek();

/* 276 */     mergeRange(to, from);
/* 277 */     visitRangeChildren(to, from);
  }

  protected void visitRangeChildren(Range to, Range from) {
/* 281 */     for (AllDuration source : from.getAllDurations().values()) {
/* 282 */       AllDuration target = to.findAllDuration(source.getValue());

/* 284 */       if (target == null) {
/* 285 */         target = new AllDuration(source.getValue());
/* 286 */         to.addAllDuration(target);
      }

/* 289 */       this.m_objs.push(target);
/* 290 */       source.accept(this);
/* 291 */       this.m_objs.pop();
    }
  }


  public void visitRange2(Range2 from) {
/* 297 */     Range2 to = (Range2)this.m_objs.peek();

/* 299 */     mergeRange2(to, from);
/* 300 */     visitRange2Children(to, from);
  }

  protected void visitRange2Children(Range2 to, Range2 from) {
/* 304 */     for (AllDuration source : from.getAllDurations().values()) {
/* 305 */       AllDuration target = to.findAllDuration(source.getValue());

/* 307 */       if (target == null) {
/* 308 */         target = new AllDuration(source.getValue());
/* 309 */         to.addAllDuration(target);
      }

/* 312 */       this.m_objs.push(target);
/* 313 */       source.accept(this);
/* 314 */       this.m_objs.pop();
    }
  }


  public void visitStatusCode(StatusCode from) {
/* 320 */     StatusCode to = (StatusCode)this.m_objs.peek();

/* 322 */     mergeStatusCode(to, from);
/* 323 */     visitStatusCodeChildren(to, from);
  }


  protected void visitStatusCodeChildren(StatusCode to, StatusCode from) {}


  public void visitTransactionReport(TransactionReport from) {
/* 331 */     TransactionReport to = (TransactionReport)this.m_objs.peek();

/* 333 */     mergeTransactionReport(to, from);
/* 334 */     visitTransactionReportChildren(to, from);
  }

  protected void visitTransactionReportChildren(TransactionReport to, TransactionReport from) {
/* 338 */     for (Machine source : from.getMachines().values()) {
/* 339 */       Machine target = to.findMachine(source.getIp());

/* 341 */       if (target == null) {
/* 342 */         target = new Machine(source.getIp());
/* 343 */         to.addMachine(target);
      }

/* 346 */       this.m_objs.push(target);
/* 347 */       source.accept(this);
/* 348 */       this.m_objs.pop();
    }
  }


  public void visitType(TransactionType from) {
/* 354 */     TransactionType to = (TransactionType)this.m_objs.peek();

/* 356 */     mergeType(to, from);
/* 357 */     visitTypeChildren(to, from);
  }

  protected void visitTypeChildren(TransactionType to, TransactionType from) {
/* 361 */     for (TransactionName source : from.getNames().values()) {
/* 362 */       TransactionName target = to.findName(source.getId());

/* 364 */       if (target == null) {
/* 365 */         target = new TransactionName(source.getId());
/* 366 */         to.addName(target);
      }

/* 369 */       this.m_objs.push(target);
/* 370 */       source.accept(this);
/* 371 */       this.m_objs.pop();
    }

/* 374 */     for (Graph2 source : from.getGraph2s().values()) {
/* 375 */       Graph2 target = to.findGraph2(source.getDuration());

/* 377 */       if (target == null) {
/* 378 */         target = new Graph2(source.getDuration());
/* 379 */         to.addGraph2(target);
      }

/* 382 */       this.m_objs.push(target);
/* 383 */       source.accept(this);
/* 384 */       this.m_objs.pop();
    }

/* 387 */     for (AllDuration source : from.getAllDurations().values()) {
/* 388 */       AllDuration target = to.findAllDuration(source.getValue());

/* 390 */       if (target == null) {
/* 391 */         target = new AllDuration(source.getValue());
/* 392 */         to.addAllDuration(target);
      }

/* 395 */       this.m_objs.push(target);
/* 396 */       source.accept(this);
/* 397 */       this.m_objs.pop();
    }

/* 400 */     if (from.getGraphTrend() != null) {
/* 401 */       GraphTrend target = to.getGraphTrend();

/* 403 */       if (target == null) {
/* 404 */         GraphTrend source = from.getGraphTrend();

/* 406 */         target = new GraphTrend(source.getDuration());
/* 407 */         to.setGraphTrend(target);
      }

/* 410 */       this.m_objs.push(target);
/* 411 */       from.getGraphTrend().accept(this);
/* 412 */       this.m_objs.pop();
    }

/* 415 */     for (Range2 source : from.getRange2s().values()) {
/* 416 */       Range2 target = to.findRange2(source.getValue());

/* 418 */       if (target == null) {
/* 419 */         target = new Range2(source.getValue());
/* 420 */         to.addRange2(target);
      }

/* 423 */       this.m_objs.push(target);
/* 424 */       source.accept(this);
/* 425 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/transaction/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */